package com.zp.manager;

import com.aliyun.oss.OSS;
import com.zp.configuration.AliyunOssClient;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 阿里云 OSS 管理器：仅保留必要操作
 */
@Component
@RequiredArgsConstructor
public class OssManager {
    private final OSS ossClient;
    private final AliyunOssClient aliyunOssClient;

    /**
     * 删除单个对象
     *
     * @param key 对象键, 域名后面的部分（以 / 开头）
     */
    public void deleteObject(String key) {
        String bucketName = aliyunOssClient.getBucket();
        // 允许传入以 "/" 开头的路径，OSS SDK 接受不带前导斜杠
        String normalizedKey = key.startsWith("/") ? key.substring(1) : key;
        ossClient.deleteObject(bucketName, normalizedKey);
    }
}